package com.ly.drivingschool.service.impl;

import com.ly.drivingschool.dao.SetmealDao;
import com.ly.drivingschool.pojo.Pager;
import com.ly.drivingschool.pojo.Setmeal;
import com.ly.drivingschool.pojo.Staff;
import com.ly.drivingschool.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    private SetmealDao setmealDao;

    /**
     * 获取全部套餐信息
     * @return
     */
    @Override
    public List<Setmeal> getAllSetmeal() {
        List<Setmeal> setmealList = setmealDao.getAllSetmeal();
        return setmealList;
    }
    /**
     * 根据id删除一条记录
     * @param setmeal_id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Integer setmeal_id) {
        int code = setmealDao.deleteByPrimaryKey(setmeal_id);
        return code;
    }

    /**
     * 批量删除多条记录
     * @param array
     * @return
     */
    @Override
    public int deleteByBatchSetmeal(int[] array) {
        int code = setmealDao.deleteByBatchSetmeal(array);
        return code;
    }

    /**
     * 添加一条新纪录
     * @param record
     * @return
     */
    @Override
    public int insertSelective(Setmeal record) {
        int code = setmealDao.insertSelective(record);
        if (code == 0) {
            return 0;
        } else {
            return 1;
        }
    }

    /**
     * 查询一条记录
     * @param setmeal_id
     * @return
     */
    @Override
    public Setmeal selectByPrimaryKey(Integer setmeal_id) {
        Setmeal setmeal = setmealDao.selectByPrimaryKey(setmeal_id);
        return setmeal;
    }

    /**
     * 更新一条记录
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(Setmeal record) {
        int code = setmealDao.updateByPrimaryKeySelective(record);
        if (code == 0) {
            return 0;
        } else {
            return 1;
        }
    }

    /**
     * 分页查询
     * @param page
     * @return
     */
    @Override
    public Pager<Setmeal> findByPager(int page, int size) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page-1)*size);
        params.put("size", size);
        Pager<Setmeal> pager = new Pager<Setmeal>();
        List<Setmeal> list = setmealDao.findByPager(params);
        pager.setData(list);
        pager.setCount(setmealDao.count());
        return pager;
    }

    @Override
    public Pager<Setmeal> findByKey(int page, int size, String keyWork) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page-1)*size);
        params.put("size", size);
        params.put("keyWork", keyWork);
        Pager<Setmeal> pager = new Pager<Setmeal>();
        List<Setmeal> list = setmealDao.findByKey(params);
        pager.setData(list);
        pager.setCount(setmealDao.countKey(keyWork));
        return pager;
    }

    @Override
    public long count() {
        return 0;
    }

    @Override
    public long countKey(String keyWork) {
        return 0;
    }

    /**
     * 查询不带字典值的信息 code
     * @param setmeal_id
     * @return
     */
    @Override
    public Setmeal findByDict(Integer setmeal_id) {
        Setmeal setmeal = setmealDao.findByDict(setmeal_id);
        return setmeal;
    }

    /**
     * 更新一条记录
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKey(Setmeal record) {
        int code = setmealDao.updateByPrimaryKeySelective(record);
        if (code == 0) {
            return 0;
        } else {
            return 1;
        }
    }

    /**
     * 添加新套餐
     * @param record
     * @return
     */
    @Override
    public int insert(Setmeal record) {
        int code = setmealDao.insertSelective(record);
        if (code == 0) {
            return 0;
        } else {
            return 1;
        }
    }
}
